package edu.uow.devdocs

import net.sf.cglib.beans.BeanCopier.Generator;

/**
 * The Person entity.
 *
 * @author    
 *
 *
 */
class Person {
	static auditable = true

	String username
	Date lastUpdated
	Person manager
	String landingPage
	// Relation
	Team team
	// Relation
	//Project project
	
	static searchable = [only: ['id','team','username']]
	
	static hasMany = [projects: Project]
	
	static mappedBy = [projects: 'persons']
	
    static mapping = {
         table 'PERSON'
         // version is set to false, because this isn't available by default for legacy databases
         version false
         id column:'PERSON_ID'
         team column:'TEAM_ID'
		 manager column:'MANAGER_ID'
         //project column:'SUB_SYSTEM_ID'
		 id generator: 'sequence', params:[sequence:'PERSON_SEQ']
		 projects joinTable: [name:"SUB_SYSTEM_PERSONS", key:'PERSON_ID', column: 'PROJECT_ID']
		 sort username:'ASC'
		 //cache usage: 'read-write'
	     }


    static constraints = {
        username(blank: false,size: 3..50)
        lastUpdated(nullable: true)
        manager(nullable: true)
        landingPage(size: 0..50)
        team()
        //project()
    }
	
	static namedQueries = {
		findByPersonAndProject  { userId,projectId->
			and {
				projects {
					eq('id',new Long(projectId))
				}
				eq('id',new Long(userId))
			}
		}
	}
	
    String toString() {
        return "${username}" 
    }
	
}
